package com.supreme.studyserver.controller;

import com.alibaba.fastjson.JSONObject;
import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.studyserver.service.ThreadJucService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "thread")
public class ThreadController {

    @Resource
    private ThreadJucService threadJucService;

    @PostMapping(value = "debugThread")
    public AjaxResp debugThread(@RequestBody JSONObject bodyData) {
        final Integer loopCount = bodyData.getInteger("loopCount");
        threadJucService.debugThread(loopCount);
        return AjaxResp.instance();
    }

    @PostMapping(value = "deadLockThread")
    public AjaxResp deadLockThread() {
        threadJucService.demoDeadLockThread();
        return AjaxResp.instance();
    }

    @PostMapping(value = "releaseThreadLock")
    public AjaxResp releaseThreadLock() {
        threadJucService.releaseThreadLock();
        return AjaxResp.instance();
    }
}
